<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class SysFileRequest extends FormRequest
{
    protected array $scenes = [
        'addGroup' => ['type', 'group_name', 'sort'],
        'editGroup' => ['group_id', 'type', 'group_name', 'sort'],
    ];
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'group_id' => 'required|integer',
            'type' => ['required', Rule::in(['image', 'video', 'file'])],
            'group_name' => 'required|min:2|max:50',
            'sort' => 'required|integer',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'group_id.required' => '参数错误-0',
            'group_id.integer' => '参数错误-1',
            'group_name.required' => '名称不能为空',
            'group_name.min' => '名称格式不正确',
            'group_name.max' => '名称格式不正确',
            'sort.required' => '排序格式错误-1',
            'sort.integer' => '排序格式错误-2',
        ];
    }
}
